<template>
  <div class="study-records-container">
    <el-card shadow="never" class="header-card">
      <div class="page-header">
        <div class="header-content">
          <el-icon class="header-icon" :size="28"><DataLine /></el-icon>
          <div class="header-text">
            <h2>学习记录</h2>
            <p>查看我的学习轨迹和数据</p>
          </div>
        </div>
      </div>
    </el-card>

    <!-- 学习数据统计 -->
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <el-statistic title="累计学习时长" :value="totalHours" suffix="小时">
            <template #prefix>
              <el-icon color="#409EFF"><Clock /></el-icon>
            </template>
          </el-statistic>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <el-statistic title="完成课程数" :value="completedCourses" suffix="门">
            <template #prefix>
              <el-icon color="#67C23A"><CircleCheck /></el-icon>
            </template>
          </el-statistic>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <el-statistic title="获得证书" :value="certificates" suffix="个">
            <template #prefix>
              <el-icon color="#E6A23C"><Medal /></el-icon>
            </template>
          </el-statistic>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <el-statistic title="学习积分" :value="points">
            <template #prefix>
              <el-icon color="#F56C6C"><StarFilled /></el-icon>
            </template>
          </el-statistic>
        </el-card>
      </el-col>
    </el-row>

    <!-- 学习趋势图 -->
    <el-card shadow="never" style="margin-top: 20px;">
      <template #header>
        <div class="card-header">
          <span>学习趋势</span>
          <el-radio-group v-model="trendPeriod" size="small">
            <el-radio-button label="week">本周</el-radio-button>
            <el-radio-button label="month">本月</el-radio-button>
            <el-radio-button label="year">本年</el-radio-button>
          </el-radio-group>
        </div>
      </template>
      <div class="trend-chart">
        <div class="chart-placeholder">
          📊 学习时长趋势图（可集成ECharts）
        </div>
      </div>
    </el-card>

    <!-- 学习记录列表 -->
    <el-card shadow="never" style="margin-top: 20px;">
      <template #header>
        <span>最近学习记录</span>
      </template>
      
      <el-timeline>
        <el-timeline-item
          v-for="record in studyRecords"
          :key="record.id"
          :timestamp="record.time"
          placement="top"
        >
          <el-card class="record-card">
            <div class="record-header">
              <div class="record-title">
                <el-icon><VideoPlay /></el-icon>
                <span>{{ record.courseName }}</span>
              </div>
              <el-tag :type="getRecordType(record.type)" size="small">
                {{ getRecordTypeName(record.type) }}
              </el-tag>
            </div>
            <div class="record-content">
              <p>{{ record.content }}</p>
              <div class="record-meta">
                <span>学习时长：{{ record.duration }}</span>
                <span v-if="record.score">得分：{{ record.score }}分</span>
              </div>
            </div>
          </el-card>
        </el-timeline-item>
      </el-timeline>
    </el-card>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import {
  DataLine, Clock, CircleCheck, Medal, StarFilled, VideoPlay
} from '@element-plus/icons-vue'

// 统计数据
const totalHours = ref(156)
const completedCourses = ref(12)
const certificates = ref(8)
const points = ref(2580)

// 趋势周期
const trendPeriod = ref('month')

// 学习记录
const studyRecords = ref([
  {
    id: 1,
    courseName: 'Vue 3 从入门到精通',
    type: 'study',
    content: '学习了"Composition API详解"章节',
    duration: '45分钟',
    time: '2024-01-15 10:30'
  },
  {
    id: 2,
    courseName: 'Vue 3 从入门到精通',
    type: 'exam',
    content: '完成了"第二章测验"',
    duration: '30分钟',
    score: 95,
    time: '2024-01-15 11:30'
  },
  {
    id: 3,
    courseName: '产品思维与方法论',
    type: 'complete',
    content: '完成了全部课程学习',
    duration: '20小时',
    time: '2024-01-10 15:20'
  },
  {
    id: 4,
    courseName: 'React开发实战',
    type: 'study',
    content: '学习了"React Hooks"章节',
    duration: '38分钟',
    time: '2024-01-14 14:00'
  }
])

// 方法
const getRecordTypeName = (type) => {
  const map = {
    study: '学习',
    exam: '考试',
    complete: '完成'
  }
  return map[type] || type
}

const getRecordType = (type) => {
  const map = {
    study: '',
    exam: 'warning',
    complete: 'success'
  }
  return map[type] || ''
}
</script>

<style scoped>
.study-records-container {
  padding: 20px;
}

.header-card {
  margin-bottom: 20px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-content {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-icon {
  color: #409EFF;
}

.header-text h2 {
  margin: 0;
  font-size: 24px;
  color: #303133;
}

.header-text p {
  margin: 4px 0 0 0;
  font-size: 14px;
  color: #909399;
}

.data-card {
  transition: all 0.3s;
}

.data-card:hover {
  transform: translateY(-4px);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.trend-chart {
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-placeholder {
  font-size: 18px;
  color: #909399;
}

.record-card {
  margin-bottom: 12px;
}

.record-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.record-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  font-size: 15px;
}

.record-content p {
  margin: 0 0 8px 0;
  color: #606266;
}

.record-meta {
  display: flex;
  gap: 20px;
  font-size: 13px;
  color: #909399;
}
</style>

